import webview


def custom_logic(window):
    window.toggle_fullscreen()
    window.evaluate_js('alert("Nice one brother")')


class Api:
    def save_note(self):
        return "hello from pywebview"


if __name__ == '__main__':
    chinese = {
        'global.quitConfirmation': u'确定关闭?',
    }

    api = Api()
    window = webview.create_window(
        title='gf-ui',
        url='./dist/index.html',
        width=900,
        height=620,
        resizable=True,  # 固定窗口大小
        text_select=True,  # 禁止选择文字内容
        confirm_close=True,  # 关闭时提示
        js_api=api,  # api中定义供html调用的函数
        min_size=(900, 620)  # 设置窗口最小尺寸
    )

    # 启动窗口
    # webview.start(localization=chinese, http_server=True, debug=True)
    # webview.start(custom_logic, window)  # 传入的函数会被立即执行
    webview.start(localization=chinese, ssl=True)  # 该语句会阻塞，直到程序关闭后才会继续执行后续代码
